package com.qingsong.controller;

import com.mybatisflex.core.paginate.Page;
import com.qingsong.dto.MenuInsertDTO;
import com.qingsong.dto.MenuPageDTO;
import com.qingsong.dto.MenuUpdateDTO;
import com.qingsong.entity.Menu;
import com.qingsong.vo.MenuSimpleListVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.qingsong.service.MenuService;

import java.util.List;

/**
 * 开发菜单表 控制层。
 *
 * @author qingsong
 * @since 2024-12-22
 */
@Tag(name = "菜单")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @Operation(summary = "新增 - 单条", description = "新增一条菜单记录")
    @PostMapping("insert")
    public boolean insert(@Validated @RequestBody MenuInsertDTO dto) {
        return menuService.insert(dto);
    }

    @Operation(summary = "查询 - 单条", description = "按主键查询一条菜单记录")
    @GetMapping("select/{id}")
    public Menu select(@PathVariable("id") Long id) {
        return menuService.select(id);
    }

    @Operation(summary = "查询 - 简单列表", description = "查询全部菜单记录,仅返回简单信息")
    @GetMapping("simpleList")
    public List<MenuSimpleListVO> simpleList() {
        return menuService.simpleList();
    }

    @Operation(summary = "查询 - 分页", description = "分页查询菜单记录")
    @GetMapping("page")
    public Page<Menu> page(@Validated MenuPageDTO dto) {
        return menuService.page(dto);
    }

    @Operation(summary = "修改 - 单条", description = "按主键修改一条菜单记录")
    @PutMapping("update")
    public boolean update(@RequestBody MenuUpdateDTO dto) {
        return menuService.update(dto);
    }

    @Operation(summary = "删除 - 单条", description = "按主键删除一条菜单记录")
    @DeleteMapping("delete/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return menuService.delete(id);
    }

    @Operation(summary = "删除 - 批量", description = "按主键批量删除菜单记录")
    @DeleteMapping("deleteBatch")
    public boolean deleteBatch(@RequestParam("ids") List<Long> ids) {
        return menuService.deleteBatch(ids);
    }
}
